<?php
namespace Manage\Controller;

class GetmessageController extends CommonController
{
    private $messageflag;
    private $phoneflag;
    public function __construct (){
        $this->messageflag = S('messageflag');
        $this->phoneflag = S('phoneflag');
        /*if(!is_numeric($this->messageflag)){
            $this->messageflag = M('cache')->find('messageflag')['value'];
        }*/
        $this->messageflag = M('cache')->find('messageflag')['value'];

        /*if(!is_numeric($this->phoneflag)){
            $this->phoneflag = M('cache')->find('phoneflag')['value'];
        }*/
        $this->phoneflag = M('cache')->find('phoneflag')['value'];
    }
    public function index(){
        $array = [
            'messageflag'=>$this->messageflag,
            'phoneflag'=>$this->phoneflag
        ];
        print_r(json_encode($array));
    }

    public function delFalg(){
        $flag = I('flag');
        self::clear($flag);
        print_r(json_encode(1));
    }

    private function clear($name='messageflag'){
        $value = M('cache')->find($name)['value'];
        $db = M('cache');
        if($value>0){
            $db->value = 0;
            $db->where(['key'=>$name])->save();
            S($name,0);
        }
    }
}
